package com.hummingbird.portal.advice;

import com.hummingbird.portal.exception.ServiceException;
import com.hummingbird.portal.r.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

// 处理 controller 异常
@RestControllerAdvice
@Slf4j
public class ExceptionControllerAdvice {
    // 发生异常时 处理的方法
    @ExceptionHandler()
    public R handleServiceException(ServiceException e) {
        log.error("发生业务异常, {}", e);
        return R.failed(e);
    }

    @ExceptionHandler()
    public R handlerException(Exception e) {
        log.error("发生未知异常, {}", e);
        return R.failed(e);
    }
}
